package Model.OtherUser;

import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DBAccess.DBAccess;

/**
 * Servlet implementation class RegistrationServlet
 */
@WebServlet("/movefriend")
public class FriendGroupServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	 @Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 new DBAccess();
		 System.out.println("HERE");
			String[] friends = request.getParameterValues("friend");
			if(friends==null){
				response.sendRedirect("friends.jsp");
				return;
			}
			String group = request.getParameter("group");
			String button = request.getParameter("button");
			int userID = Integer.parseInt(request.getParameter("userID"));
			if(button.equals("New"))
				group = request.getParameter("newgroup");
			if (group == null){
				group = "";
			}

			for (int i = 0; i<friends.length; i++){
				int friend = Integer.parseInt(friends[i]);
				DBAccess.updateOtherUser(userID, friend, Friends.FRIEND, group);
			}
			
			response.sendRedirect("friends.jsp");
			return;

		}

}
